package mq

import (
	"cloud-disk/global/mq"
	amqp "github.com/rabbitmq/amqp091-go"
	"log"
)

func Publish(exchange, routingKey string, data []byte) bool {
	if !mq.InitChannel() {
		return false
	}
	err := mq.Channel().Publish(exchange, routingKey, false, false, amqp.Publishing{
		ContentType:  "text/plain",
		DeliveryMode: amqp.Persistent,
		Body:         data,
	})
	if err != nil {
		log.Printf("fail to deliver data, err : %v\n", err.Error())
		return false
	}
	return true
}
